package com.aurora.app.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.aurora.app.dao.ThingStoryDao;
import com.aurora.app.entity.ThingStory;
import com.aurora.app.enums.FakeDelete;
import com.aurora.base.dao.BaseDao;
import com.aurora.base.service.BaseService;
@Service
public class ThingStoryService extends BaseService<ThingStory> {
	@Resource
	private ThingStoryDao baseDao;
	@Override
	public BaseDao<ThingStory> getBaseDao() {
		// TODO 自动生成的方法存根
		return this.baseDao;
	}

	/**
	 * 获取列表
	 * @param first
	 * @param max
	 * @return
	 */
	public List<ThingStory> getListByPages(int first,int max){
		return this.baseDao.list(first,max,"o.isDelete = ? ",FakeDelete.NODELETE);
	}
	
	/**
	 * 获取列表
	 * @param first
	 * @param max
	 * @return
	 */
	public List<ThingStory> getListByTopicId(int first,int max,String topicId,String searchKey){
		if(!StringUtils.isEmpty(searchKey)){
			return this.baseDao.list(first,max,"o.isDelete = ? and (o.title like ? or o.content like ?)",FakeDelete.NODELETE,"%"+searchKey+"%","%"+searchKey+"%");
		}else{
			return this.baseDao.list(first,max,"o.isDelete = ? and o.storyTopic.id = ?",FakeDelete.NODELETE,topicId);
		}
	}
	
	
}
